<!DOCTYPE html>
<html>
  <head>
    <title>留言板</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel='stylesheet' href='/stylesheets/style.css' />
  </head>
  <body>
    <h1>留言板</h1>
    <% if (user) { %>
      <div>
        <h4><%= user %>已登录</h4>
        <form action="/users/post-review" method="post" id="post-review-form">
          <textarea name="post-review" id="post-review" cols="30" rows="10"></textarea>
          <button type="submit">发表留言</button>
        </form> 
        <p><a href="/users/logout">退出登录</a></p>
      </div>
    <% } else { %>
      <form action="/users/reg" method="post">
        <input type="text" name="regname" id="regname" placeholder="注册用户名">
        <input type="password" name="password" id="reg-psd" placeholder="密码">
        <input type="password" name="confirm" id="reg-confirm" placeholder="重复密码">
        <span>验证图片</span><img src="/users/vimg" alt=""><input type="text" name="vimg" id="reg-vimg">
        <button type="submit">注册</button>
      </form>
      <form action="/users/login" method="post">
        <input type="text" name="loginname" id="loginname" placeholder="登录帐号">
        <input type="password" name="psd" id="login-psd" placeholder="密码">
        <%= firstnum %> + <%= secondnum %> = <input type="text" name="vnum" id="login-vnum">
        <button type="submit">登录</button>
      </form>
    <% } %>
    <div class="reviews">
      <h2>留言信息</h2>
      <% if (reviews.length !== 0) { %>
        <% reviews.forEach(review => { %>
          <div class="review">
            <p>用户: <%= review.username %></p>
            <p><%= review.contents %></p>
          </div>
        <% }) %>
      <% } %>
    </div>
  </body>
</html>
